﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.ServiceLocation;
using Renci.iRods.Studio.Common.Events;

namespace Renci.iRods.Studio.Common
{
    public class ApplicationState
    {
        public static ApplicationState _current = new ApplicationState();
        /// <summary>
        /// Gets the current instance of application state.
        /// </summary>
        public static ApplicationState Current
        {
            get { return _current; }
        }

        private ConnectionChnagedEvent _connectionChangedEvent;

        private ApplicationState()
        {
            var eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
            this._connectionChangedEvent = eventAggregator.GetEvent<ConnectionChnagedEvent>();
        }

        private IRodsConnection _connection;
        /// <summary>
        /// Gets or sets application connection.
        /// </summary>
        /// <value>
        /// The connection.
        /// </value>
        public IRodsConnection Connection
        {
            get
            {
                return this._connection;
            }
            set
            {
                if (this._connection != value)
                {
                    this._connection = value;
                    this._connectionChangedEvent.Publish(value);
                }
            }
        }
    }
}
